<template>
	<view class="page page-bg">
		<view class="tab-wraps">
			<u-tabs :list="list" :is-scroll="false" :current="current" active-color='#0bbf68' bg-color='transparent' @change="changeTab"></u-tabs>
		</view>
		<view class="meet-list content-20">
			<view class="meet-item" v-for="item in items" :key='item.id' @click="$link('/pagesMine/doctorWzDetail?id='+item.id)">
				<view class="meet-info">
					<view class="info">
						<view class="meet-title">{{item.title}}</view>
						<view class="desc">{{item.creationTime | formatTime}}</view>
					</view>
					<view class="btn-theme" v-if="current===0">去回答</view>
					<view class="btn-theme" v-else>查看回答</view>
				</view>
			</view>
		</view>
		<view class="no-info">{{text}}</view>
	</view>
</template>

<script>
	import common from '../utils/common.js'
	import api from '../utils/api.js'
	export default {
		data() {
			return {
				list: [
					{ name: '未回答', value: 0 }, 
					{ name: '已回答', value: 1 },
				],
				current: 0,
				pageIndex: 1,
				pageSize: 10,
				totalCount: 0,
				items: [],
				text: '暂无相关信息~'
			}
		},
		
		onLoad() {
			this.pageSize = common.pageSize
			this.getItems()
		},
		
		methods: {
			changeTab(index) {
				this.current = index;
				this.pageIndex = 1
				this.items = []
				this.getItems()
			},
			
			getItems() {
				let {current, pageIndex, pageSize} = this.$data
				api.getAllOnlineConsultationPage({ state: current, pageIndex, pageSize},(res) => {
					 this.totalCount = res.totalCount
					 if(this.pageSize > res.totalCount) { this.text = '已经没有更多了~' }
					 let temp = res.items
					 if(this.pageIndex !== 1) {
					     temp = [...this.items, ...res.items]
					 }
					 this.items = temp
				}) 
			}
		},
		
		onReachBottom() {
			if(this.pageIndex * this.pageSize >= this.totalCount) {
				this.text = '已经没有更多了~'
			}else{
				this.pageIndex ++
				this.getItems()
			}
		}
	}
</script>

<style scoped lang="scss">
	.tab-wraps{
		background-color: #fff;
	}
	.meet-item{
		background-color: #fff;
		border-radius: 10upx;
		padding: 20upx;
		box-sizing: border-box;
		margin-bottom: 20upx;
	}
	
	.meet-title{
		font-size: $font-size-30;
		font-weight: bold;
	}
	
	.meet-info{
		@include flex-base;
		justify-content: space-between;
	}
	.info{
		display: flex;
		flex-direction: column;
	}
	
	.desc{
		background-image: url(../static/icon_10.png);
		background-size: 20upx 20upx;
		background-repeat: no-repeat;
		background-position: left center;
		padding-left: 35upx;
		margin-top: 20upx;
	}
	
</style>
